package com.ubs.training.web.util;

import com.ubs.training.server.dao.model.Rating;
import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;

/**
 * Created with IntelliJ IDEA.
 * User: xubuntu
 * Date: 8/24/12
 * Time: 2:46 AM
 * To change this template use File | Settings | File Templates.
 */
public class RatingValidator {

    private Rating rating;
    private Errors res;

    public RatingValidator(Rating rating, Errors res) {
        this.rating = rating;
        this.res = res;
    }

    public void validate() {

        if(!StringUtils.hasLength(rating.getRatingValue())){
            res.rejectValue("ratingValue", "empty", " Please provide a rating value.");
        }
        if(rating.getRatingValue().length() > 5){

            res.rejectValue("ratingValue", "toolong", " Rating value should be no longer than 5 symbols.");
        }
        if(rating.getCountrySpecific() < 0 || rating.getCountrySpecific() > 1){

            res.rejectValue("countrySpecific", "incompatible", " Please enter '1' for TRUE or '0' for FALSE.");
        }
    }
}
